/*
 * @Description: 公共模块（字典等）
 * @Author: Haor
 * @Date: 2022-04-06 21:07:26
 * @LastEditTime: 2022-04-08 11:49:14
 * @LastEditors: Haor
 */

import {
    Controller,
    Get,
    Post,
    Body,
    Patch,
    Param,
    Delete, Query
} from "@nestjs/common";
import { CommonService } from './common.service'
import { Permission } from "@decorators";
import { CreateCommonDto } from './dto/create-common.dto'
import { UpdateCommonDto } from './dto/update-common.dto'
import { BatchQueryDto } from './dto/batch-query-dict.dto'
import { CreateDictDto, CreateDictValueDto, GetDictListDto } from "@dto/dict.dto";

@Controller('common')
export class CommonController {
    constructor(private readonly commonService: CommonService) {}

    @Post()
    create(@Body() createCommonDto: CreateCommonDto) {
        return this.commonService.create(createCommonDto)
    }

    @Get('/all/dict')
    findAll() {
        return 'test all dict'
    }

    @Get(':id')
    findOne(@Param('id') id: string) {
        return this.commonService.findOne(+id)
    }

    @Patch(':id')
    update(@Param('id') id: string, @Body() updateCommonDto: UpdateCommonDto) {
        return this.commonService.update(+id, updateCommonDto)
    }

    @Delete(':id')
    remove(@Param('id') id: string) {
        return this.commonService.remove(+id)
    }

    @Post('/dict/name_list')
    getDictNameList(@Body() params: GetDictListDto) {
        return this.commonService.getDictNameList(params)
    }

    @Get('/dict/list')
    getDictList() {
        return this.commonService.getDictList()
    }

    @Post('/dict/create')
    @Permission('dict::create')
    createDict(@Body() params: CreateDictDto) {
        return this.commonService.createDict(params)
    }

    //创建字典值
    @Post('/dict/create/:id')
    @Permission('dict::create_value')
    createDictValue(
        @Param('id') dictId: number,
        @Body() params: CreateDictValueDto
    ) {
        return this.commonService.createDictValue(dictId, params)
    }

    @Delete('/dict/value/:valueId')
    @Permission('dict::delete_value')
    deleteDictValue(@Param('valueId') valueId: number) {
        return this.commonService.deleteDictValue(+valueId)
    }

    /**
     * 批量查询字典列表
     * @param nameList
     */
    @Post('/dict/batch_list')
    @Permission('dict::batch_list')
    getDictBatchList(@Body() nameList: BatchQueryDto) {
        return this.commonService.getDictBatchList(nameList)
    }

    /**
     * 批量查询字典列表
     * @param nameList
     */
    @Delete('/dict/:id')
    @Permission('dict::delete_value')
    deleteDictById(@Param('id') id: string) {
        return this.commonService.deleteDictById(+id)
    }

    @Post('/dict/export')
    @Permission('dict::export')
    exportDict() {
        return this.commonService.exportDict()
    }
}
